﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MVVM.ViewModels
{
    public class ActionCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            if (this.CanExecuteFunc == null)
                return true;
            return this.CanExecuteFunc(parameter);
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (this.ExecuteAction != null)
                this.ExecuteAction(parameter);
        }

        private Action<object> ExecuteAction { get; set; }

        private Func<object, bool> CanExecuteFunc { get; set; }

        public ActionCommand(Action<object> executeMethod)
        {
            this.ExecuteAction = executeMethod;
        }

        public ActionCommand(Action<object> executeMethod, Func<object, bool> canExecuteMethod)
        {
            this.ExecuteAction = executeMethod;
            this.CanExecuteFunc = canExecuteMethod;
        }
    }
}
